import numpy as np    # Python中进行数值计算的库
import pandas as pd    # Python中进行数据处理的库
import warnings

from markdown_it.rules_core import inline

warnings.filterwarnings('ignore') #  忽略弹出的warnings

data = pd.read_csv('Lending_Club.csv',encoding="ISO-8859-1")
data.shape #查看数据量大小
data.head(6)#查看部分数据

print("revol_util特征列的异常样本数为: ", data[data['revol_util'] > 1].shape[0]) #数据使用的是小数，所以大于1的就是异常数据
data.drop(data[data['revol_util'] > 1].index, inplace = True)    # 根据索引删除样本

#import seaborn as sns
#import matplotlib.pyplot as plt    # 可视化
# 在Jupyter notebook里嵌入图片
#matplotlib.inline

#ax = sns.distplot(data['dti'],kde=True,hist=False)
#plt.show()

# 去掉高于100的部分再次观察
#norDf = data[data['dti'] <= 100.0]
#sns.distplot(norDf['dti'],kde=True,hist=False)
#plt.show()


# 绘制箱型图分析
bp_list = list(data['annual_inc'])

#plt.figure(figsize=(20,4)) # 建立图像
#plt.boxplot(bp_list, vert=False, flierprops = {"marker":"o","markerfacecolor":"steelblue"})
#plt.show() # 展示箱型图

# 箱型图的边界
q1 = data['annual_inc'].describe()['25%']
q3 = data['annual_inc'].describe()['75%']
iqr = q3 - q1
print("箱型图上须：", q3 + 1.5*iqr)
print("箱型图下须：", q1 - 1.5*iqr)


data.loc[data['annual_inc'] > 1500000.0, 'annual_inc'] = 1500000.0    # 固定值替代
print("此时annual_inc特征列还有%d个大于150万的特征值" % (data[data['annual_inc'] > 1500000.0]).shape[0])
